<template>
	<view class="body">
		<input type="email"  class="uni-input common-input" placeholder="输入你要绑定的邮箱" v-model="email">
		<input type="text" password class="uni-input common-input" placeholder="输入密码" v-model="password">
		<button type="primary" class="user-set-btn" :loading="loading" hover-class="exit-hover" :class="{'user-set-btn-disabled': disabled}" @tap="submit" :disabled="disabled">完成</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				email:"",
				password:"",
				disabled:true,
				loading:false
			}
		},
		methods: {
			
				submit(){
					if(!this.check()){return ;}
					
					this.loading = true
					setTimeout(()=>{
						uni.showToast({
							title:"验证通过",
							icon:"success",
							duration:1500
						})
						this.loading = false
					},1500)
				},
				check(){
					if(!this.email || this.email==""){
						uni.showToast({
							title:"旧密码不能为空",
							icon:"none"
						})
						return false;
					}
					if(!this.password || this.password==""){
						uni.showToast({
							title:"密码不能为空",
							icon:"none"
						})
						return false;
					}
					let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
					if(!reg.test(this.email)){
						uni.showToast({
							title:"邮箱格式有误",
							icon:"none"
						})
						return false
					}
					return true;
					
				},
				change(){
					if(this.email && this.password){
						this.disabled = false
						return ;
					}
					this.disabled = true
				}
			
		},
		watch:{
			email(val){
				this.change()
			},
			password(val){
				this.change()
			},
		},
		// 监听页面返回
		onBackPress(){
			uni.hideKeyboard()
		}
	}
</script>

<style>
	@import "../../common/form.css";
	.exit-hover {
		background: #DECE4B!important;
	} 
</style>
